require "Net/drawHandler"
---@class UIDrawAward : UIBase
UIDrawAward = UIBase.New(PanelResNames.UIDrawAward)
local t = UIDrawAward
--- 暂不再使用,整合到了UIDrawPond里面
function t.Init()
    --t.showType = _type
    --t.sequence = sequence
    --t.index = index
    --t.itemId = itemId
    UIBase.Init(t)
end

function t:OnCreate()
    -----@type GList
    self.closeBtn = self:GetChild("back")
    self:GetChild("title").text = getLanguage("WishFountain_RewardList_Title");
    self.SumNumTextAward = self:GetChild("allnum")
    self.dynamicAwardList = self:SetDynamicList(self:GetChild("glist"), self.setData, nil, true, true)

    self:RegisterOnClick(self.closeBtn, self.ClickClose)

end
--- 暂不再使用,整合到了UIDrawPond里面
function t:Refresh()

    local tConfg = G.dataTable["t_wishfountain"]
    self.ShowKeyAwardTab = {}

    local showCard = {}
    local SumNum = 0;
    showCard.itemid = 201500 + drawHandler.WishSource.bigRewardID;
    if (drawHandler.WishSource.drawBigReward == 0) then
        showCard.num = 1
        SumNum = 1;
    else
        showCard.num = 0
    end
    showCard.heroiD = drawHandler.WishSource.bigRewardID;
    table.insert(self.ShowKeyAwardTab, showCard)

    for i = 1, #drawHandler.WishSource.wishRewardInfo do
        local tempWish = drawHandler.WishSource.wishRewardInfo[i]
        local RNum = tempWish.rewardCount;
        if (tempWish.type == 1 or tempWish.type == 3) then
            SumNum = SumNum + RNum;
            local keyID = tempWish.items[1].itemID;
            local showD = {}
            showD.itemid = keyID;
            showD.num = RNum
            table.insert(self.ShowKeyAwardTab, showD)
        end
    end

    self.ConfigKeyAwardTab = {};
    local ConfigNum = 0;
    for k, v in pairs(tConfg) do
        local tempPond = decodeJsonStrToTabel(v.f_ItemGroup);
        for i = 1, #tempPond do
            local AwardID = tempPond[i][1];
            local iconNum = tempPond[i][2];-- v.f_ItemGroupNum
            self.ConfigKeyAwardTab[tostring(AwardID)] = iconNum
        end
        ConfigNum = ConfigNum + v.f_ItemGroupNum;
    end
    ConfigNum = ConfigNum + 1;--大奖数量

    self.SumNumTextAward.text = SumNum .. "/" .. ConfigNum

    self.dynamicAwardList.numItems = #self.ShowKeyAwardTab;
end
--- 暂不再使用,整合到了UIDrawPond里面
function t:setData(index, itemobj)
    local itemValue = self.ShowKeyAwardTab[index];
    local go = itemobj;
    local itemRoot = go:GetChild("item");
    local sum = go:GetChild("sum");
    local itemname = go:GetChild("itemname");
    local gray = go:GetController("gray");
    local confItem = G.dataTable["t_item"][tostring(itemValue.itemid)]
    local num;
    if self.ConfigKeyAwardTab[tostring(itemValue.itemid)] ~= nil then
        num = self.ConfigKeyAwardTab[tostring(itemValue.itemid)]
    end
    if itemValue.heroiD ~= nil then
        num = 1;
    end
    logicMgr.CostManager.RefreshItem(itemRoot, { itemValue.itemid, num });
    itemname.text = getLanguage(confItem.f_ItemName);
    sum.text = itemValue.num;
    if itemValue.num == 0 then
        gray.selectedIndex = 1;
    else
        gray.selectedIndex = 0;
    end
end

--
--function t:RestWish()
--    drawHandler.GoReqResetWishMessage();
--end

--function t:RefreshItemList()
--self.itemDataList = self:GetDropByItemId(self.itemModelId)
--self.itemList.numItems = #self.itemDataList
--end

--function t:InitData()
--
--end

--function t:onClickitem(index, num)
--    if (index ~= nil) then
--        local data = {}
--        data = logicMgr.ItemManager.getItemConstDatabyModelId(index);
--        data["num"] = num
--        showUI(PanelNames.UIBagItemInfo, data, 1);
--    end
--end

--function t:ParseItemFunc(str)
--    self.itemFunc = decodeJsonStrToTabel(str)
--end
function t:OnEnable()
    self:Refresh()
end
function t:OnDisable()
    self:RemoveTimeCall(self.UpdateTime)
end
function t:OnDestroy()

end

function t:ClickClose()
    closeUI(PanelResNames.UIDrawAward)
end

return t
